package com.danco.training.zaneuskaya.cswworker;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import org.apache.log4j.Logger;

public class CSVReader {

	private static final Logger logger = Logger.getLogger(CSVReader.class);
	private static BufferedReader br = null;
	private static String line = "";
	private static String separator = Separator.SEPARATOR.getS();
	private static String[] entities = null;

	public static String[] readFile(String file) {

		try {

			br = new BufferedReader(new FileReader(file));
			while ((line = br.readLine()) != null) {

				entities = line.split(separator);

			}

		} catch (FileNotFoundException e) {
			logger.error(e.getMessage(), e);
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					logger.error(e.getMessage(), e);
				}
			}
		}

		return entities;

	}

	public static <T> List<T> readList(String file) {
		List<T> res = new ArrayList<T>();
		res.toArray(readFile(file));
		return res;

	}

}
